/**
 * 系统资源js
 */
var sysParameter= {
	curPage:1,
	pageSize:10,
	dataCache:null,
	
	startEvent:function(){
		//按回车键登录事件
		document.onkeydown = function(e){ 
    		var ev = document.all ? window.event : e;
    		if(ev.keyCode==13) {
    			sysParameter.curPage=1;
    			sysParameter.setPageChange(null);
    			sysParameter.search();
     		}
		};
	},
	
	bindEvent:function(){	
		//查询
		$('#searchData').click(function(){
			sysParameter.curPage=1;
			sysParameter.setPageChange(null);
			sysParameter.search();
		});
		
		$('#addData').on('click',function(){
			var path=APP_ADDRESS+'mgr/sysMgr/parameter/sysParameterAdd.jsp';
			art.dialog.open(path, {
			    title: '添加参数',
			    width: 450,
			    height:350,
			   ok: function () {
				   var returnStatus=this.iframe.contentWindow.submitForm();
				   if(returnStatus){
					   sysParameter.setPageChange(null);
					   sysParameter.search();
					   art.dialog.close();
				   }
				   return returnStatus;
			    },
			    cancel: true
			});
		});
	},
	
	//设置分页
	setPageChange:function(delCurPage){
		var url = 'mgr/parameterCtrl/list';
		var name=$.trim($('#searchModForm input[name="name"]').val());
		var params={
			'curPage':1,
			'pageSize':9999,
			'name':name,
		};
		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / sysParameter.pageSize > 0) ? Math.ceil(totalCount/ sysParameter.pageSize) : 1;
				pageHelper.init(pageTotal,totalCount,sysParameter.search,delCurPage);  //翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	//查询版本信息
	search:function(pageIdx){
		
		
		var url = 'mgr/parameterCtrl/list';
		if (typeof(pageIdx) != "undefined"){ 
			sysParameter.curPage=pageIdx;
		}
		
		var name=$.trim($('#searchModForm input[name="name"]').val());
		var params={
			'curPage':sysParameter.curPage,
			'pageSize': sysParameter.pageSize,
			'name':name,
		};
		
		var cb = function(data) {
			if (data.resultCode == 200) {
				$('#tableList tbody').empty();
				var tr='';
				if(data.result!=null&&data.result.length>0){
					for(var i=0;i<data.result.length;i++){
						
						var singleObj=data.result[i];
						 
						localStorage.setItem(singleObj.id + "_Parameter_Key", JSON.stringify(singleObj));
						
						tr +='<tr><td>'
							+ '<input type="hidden" id ="id" name="id" value="'+singleObj.id+'"/>'
							+ (i+1)
							+ '</td><td>'
							+  singleObj.name 
							+ '</td><td>'
							+ singleObj.flag    
							+ '</td><td>'
							+ singleObj.descStr  
							+ '</td><td>'
							+ (singleObj.value01!=null?singleObj.value01 :"")
							+ '</td><td>'
							+ (singleObj.value02!=null?singleObj.value02 :"")
							+ '</td><td>'
							+  (singleObj.value03!=null?singleObj.value03 :"")
							+ '</td><td>'
							+  (singleObj.value04!=null?singleObj.value04 :"")
							+ '</td><td>'
							+'<a type="button" name="sysParameter_96" id="btnUpdate" style="margin-left: 5px;display:none;" class="btn btn-success btn-xs updateData" style="margin-left: 5px;">'
							+'<i class="fa fa-edit"></i>修改</a>'
							+'</td></tr>';
					}
					
				}else{
					tr='<tr><td colspan="6" style="text-align: center;color: red;">暂无数据</td></tr>';
				}
				$('#tableList tbody').html(tr);
				
				sysParameter.bindEventOtherBtn();
				jsUtils.controlFunctionBtn();
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	bindEventOtherBtn:function(){
		$('.updateData').unbind();
		$('.updateData').on('click',function(){
			var thisObj=$(this);
			var id=thisObj.parent().parent().find('input[name="id"]').eq(0).val();
			art.dialog.data('updId', id);
			var path=APP_ADDRESS+'mgr/sysMgr/parameter/sysParameterUpdate.jsp';
			art.dialog.open(path, {
			    title: '修改参数',
			    width:450,
			    height:350,
			   ok: function () {
				   var returnStatus=this.iframe.contentWindow.submitForm();
				   if(returnStatus){
					   sysParameter.setPageChange(sysParameter.curPage);
					   sysParameter.search(sysParameter.curPage);
					   art.dialog.close();
				   }
				   return returnStatus;
			    },
			    cancel: true
			});
		});
		$('.lookData').unbind();
		$('.lookData').on('click',function(){
			var thisObj=$(this);
			var id=thisObj.parent().parent().find('input[name="id"]').eq(0).val();
			art.dialog.data('id', id);
			var path=APP_ADDRESS+'mgr/sysMgr/parameter/sysParameterLook.jsp';
			art.dialog.open(path, {
			    title: '查看系统参数',
			    width: 600,
			    height:450,
			    cancel: true
			});
		});
	},
		
	init : function() {
		sysParameter.setPageChange(null);
		sysParameter.search();
		sysParameter.startEvent();
		sysParameter.bindEvent();
	}
};

$(document).ready(function() {
	sysParameter.init();
});

//提供给外部刷新调用
function refashData(){
	sysParameter.setPageChange(null);
	sysParameter.search();
}


